import request from '@/utils/request'

export const permissionApi = {
  // 获取权限列表 - 已接入后端
  getPermissions(params = {}) {
    return request.get('/permission', { params })
  },

  // 分页获取权限列表
  getPermissionsPaged(pageIndex = 0, pageSize = 10, filters = {}) {
    return request.get('/permission/paged', {
      params: {
        pageIndex,
        pageSize,
        ...filters
      }
    })
  },

  // 获取权限详情 - 后端缺失，需要补充
  getPermissionById(id) {
    return request.get(`/permission/${id}`)
  },

  // 创建权限 - 已接入后端
  createPermission(data) {
    return request.post('/permission', data)
  },

  // 更新权限 - 已接入后端
  updatePermission(id, data) {
    return request.put(`/permission/${id}`, data)
  },

  // ❌ 以下接口后端未实现，需要补充

  // 删除权限 - 已接入后端
  deletePermission(id) {
    return request.delete(`/permission/${id}`)
  },

  // 级联删除权限（包括子权限）- 已接入后端
  deleteCascadePermission(id) {
    return request.delete(`/permission/${id}/cascade`)
  },

  // 批量删除权限 - 已接入后端
  batchDeletePermissions(ids) {
    return request.post('/permission/batch-delete', ids)
  },

  // 获取权限树形结构 - 后端缺失
  getPermissionTree() {
    return request.get('/permission/tree')
  },

  // 获取用户权限 - 后端缺失
  getUserPermissions(userId) {
    return request.get(`/permission/user/${userId}`)
  },

  // 获取角色权限 - 后端缺失
  getRolePermissions(roleId) {
    return request.get(`/permission/role/${roleId}`)
  },

  // 获取顶级权限作为分组
  getTopLevelPermissions() {
    return request.get('/permission/top-level')
  }
}
